 //自己实现一个阻塞队列
/*public class MyblockingQueue {
     public int[] arr = new int[1000];
     int start = 0;
     int end = 0;
     public int size = 0;

     public void put(int a) {
         synchronized (this) {
           //判断队列元素是否满了
             while (size == arr.length) {
                 try {
                 如果队列元素满了就阻塞等待一下

                     this.wait();

                 } catch (InterruptedException e) {
                     throw new RuntimeException(e);
                 }
             }
             arr[end] = a;
             end++;
             if (end >= arr.length) {
                 end = 0;
             }
             size++;
             一旦增加元素，就通知一下正在阻塞等待取元素的线程
             this.notify();
         }
     }

     public int take() {
         synchronized (this) {
         //判断队列元素是否为空
             while (size == 0) {
                 try {
                   //如果为空就阻塞等待一下
                     this.wait();

                 } catch (InterruptedException e) {
                     throw new RuntimeException(e);
                 }
             }
             int a = arr[start];
             start++;
             if (start >= arr.length) {
                 start = 0;
             }
             size--;
             //一旦有元素被取出，就通知一下正在阻塞等待放元素的线程
             this.notify();
             return a;

         }
     }
 }

class text91{
        public static void main(String[] args) {
            MyblockingQueue myblockingQueue=new MyblockingQueue();
            Thread producer=new Thread(()->{
                int count=0;
                while(true)
                {
                    myblockingQueue.put(count);
                    System.out.println("生产者:"+count);
                    count++;
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }

                }

            });
            Thread consumer=new Thread(()->{
                while(true)
                {
                    int a=myblockingQueue.take();
                    System.out.println("消费者:"+a);
                }

            });
            producer.start();
            consumer.start();

        }


    }

  */






